﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace hcrainMvc.DAL
{
	/// <summary>
	/// 数据访问类:herp_store
	/// </summary>
	public partial class herp_store
	{
		public herp_store()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(long id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from herp_store");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(hcrainMvc.Model.herp_store model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into herp_store(");
			strSql.Append("inouttype,gid,orderid,orderno,inorderlistid,storehouseid,spmaintype,spsubtype,productid,productgid,productname,storeall,price,hasoutall,unit,jgcount,owneruserid,lockcout,dataadduserid,datadepid,databranchid,datadepname,databranchname,dataaddusername,dataaddtime,insertforlog,inguid)");
			strSql.Append(" values (");
			strSql.Append("@inouttype,@gid,@orderid,@orderno,@inorderlistid,@storehouseid,@spmaintype,@spsubtype,@productid,@productgid,@productname,@storeall,@price,@hasoutall,@unit,@jgcount,@owneruserid,@lockcout,@dataadduserid,@datadepid,@databranchid,@datadepname,@databranchname,@dataaddusername,@dataaddtime,@insertforlog,@inguid)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@inouttype", MySqlDbType.VarChar,10),
					new MySqlParameter("@gid", MySqlDbType.VarChar,36),
					new MySqlParameter("@orderid", MySqlDbType.Int64,20),
					new MySqlParameter("@orderno", MySqlDbType.VarChar,100),
					new MySqlParameter("@inorderlistid", MySqlDbType.Int64,20),
					new MySqlParameter("@storehouseid", MySqlDbType.Int64,20),
					new MySqlParameter("@spmaintype", MySqlDbType.VarChar,80),
					new MySqlParameter("@spsubtype", MySqlDbType.VarChar,80),
					new MySqlParameter("@productid", MySqlDbType.Int64,20),
					new MySqlParameter("@productgid", MySqlDbType.VarChar,36),
					new MySqlParameter("@productname", MySqlDbType.VarChar,100),
					new MySqlParameter("@storeall", MySqlDbType.Decimal,10),
					new MySqlParameter("@price", MySqlDbType.Decimal,10),
					new MySqlParameter("@hasoutall", MySqlDbType.Decimal,10),
					new MySqlParameter("@unit", MySqlDbType.VarChar,40),
					new MySqlParameter("@jgcount", MySqlDbType.Decimal,10),
					new MySqlParameter("@owneruserid", MySqlDbType.Int64,20),
					new MySqlParameter("@lockcout", MySqlDbType.Decimal,10),
					new MySqlParameter("@dataadduserid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepid", MySqlDbType.Int32,11),
					new MySqlParameter("@databranchid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepname", MySqlDbType.VarChar,100),
					new MySqlParameter("@databranchname", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddtime", MySqlDbType.DateTime),
					new MySqlParameter("@insertforlog", MySqlDbType.Int32,11),
					new MySqlParameter("@inguid", MySqlDbType.VarChar,36)};
			parameters[0].Value = model.inouttype;
			parameters[1].Value = model.gid;
			parameters[2].Value = model.orderid;
			parameters[3].Value = model.orderno;
			parameters[4].Value = model.inorderlistid;
			parameters[5].Value = model.storehouseid;
			parameters[6].Value = model.spmaintype;
			parameters[7].Value = model.spsubtype;
			parameters[8].Value = model.productid;
			parameters[9].Value = model.productgid;
			parameters[10].Value = model.productname;
			parameters[11].Value = model.storeall;
			parameters[12].Value = model.price;
			parameters[13].Value = model.hasoutall;
			parameters[14].Value = model.unit;
			parameters[15].Value = model.jgcount;
			parameters[16].Value = model.owneruserid;
			parameters[17].Value = model.lockcout;
			parameters[18].Value = model.dataadduserid;
			parameters[19].Value = model.datadepid;
			parameters[20].Value = model.databranchid;
			parameters[21].Value = model.datadepname;
			parameters[22].Value = model.databranchname;
			parameters[23].Value = model.dataaddusername;
			parameters[24].Value = model.dataaddtime;
			parameters[25].Value = model.insertforlog;
			parameters[26].Value = model.inguid;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(hcrainMvc.Model.herp_store model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update herp_store set ");
			strSql.Append("inouttype=@inouttype,");
			strSql.Append("gid=@gid,");
			strSql.Append("orderid=@orderid,");
			strSql.Append("orderno=@orderno,");
			strSql.Append("inorderlistid=@inorderlistid,");
			strSql.Append("storehouseid=@storehouseid,");
			strSql.Append("spmaintype=@spmaintype,");
			strSql.Append("spsubtype=@spsubtype,");
			strSql.Append("productid=@productid,");
			strSql.Append("productgid=@productgid,");
			strSql.Append("productname=@productname,");
			strSql.Append("storeall=@storeall,");
			strSql.Append("price=@price,");
			strSql.Append("hasoutall=@hasoutall,");
			strSql.Append("unit=@unit,");
			strSql.Append("jgcount=@jgcount,");
			strSql.Append("owneruserid=@owneruserid,");
			strSql.Append("lockcout=@lockcout,");
			strSql.Append("dataadduserid=@dataadduserid,");
			strSql.Append("datadepid=@datadepid,");
			strSql.Append("databranchid=@databranchid,");
			strSql.Append("datadepname=@datadepname,");
			strSql.Append("databranchname=@databranchname,");
			strSql.Append("dataaddusername=@dataaddusername,");
			strSql.Append("dataaddtime=@dataaddtime,");
			strSql.Append("insertforlog=@insertforlog,");
			strSql.Append("inguid=@inguid");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@inouttype", MySqlDbType.VarChar,10),
					new MySqlParameter("@gid", MySqlDbType.VarChar,36),
					new MySqlParameter("@orderid", MySqlDbType.Int64,20),
					new MySqlParameter("@orderno", MySqlDbType.VarChar,100),
					new MySqlParameter("@inorderlistid", MySqlDbType.Int64,20),
					new MySqlParameter("@storehouseid", MySqlDbType.Int64,20),
					new MySqlParameter("@spmaintype", MySqlDbType.VarChar,80),
					new MySqlParameter("@spsubtype", MySqlDbType.VarChar,80),
					new MySqlParameter("@productid", MySqlDbType.Int64,20),
					new MySqlParameter("@productgid", MySqlDbType.VarChar,36),
					new MySqlParameter("@productname", MySqlDbType.VarChar,100),
					new MySqlParameter("@storeall", MySqlDbType.Decimal,10),
					new MySqlParameter("@price", MySqlDbType.Decimal,10),
					new MySqlParameter("@hasoutall", MySqlDbType.Decimal,10),
					new MySqlParameter("@unit", MySqlDbType.VarChar,40),
					new MySqlParameter("@jgcount", MySqlDbType.Decimal,10),
					new MySqlParameter("@owneruserid", MySqlDbType.Int64,20),
					new MySqlParameter("@lockcout", MySqlDbType.Decimal,10),
					new MySqlParameter("@dataadduserid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepid", MySqlDbType.Int32,11),
					new MySqlParameter("@databranchid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepname", MySqlDbType.VarChar,100),
					new MySqlParameter("@databranchname", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddtime", MySqlDbType.DateTime),
					new MySqlParameter("@insertforlog", MySqlDbType.Int32,11),
					new MySqlParameter("@inguid", MySqlDbType.VarChar,36),
					new MySqlParameter("@id", MySqlDbType.Int64,20)};
			parameters[0].Value = model.inouttype;
			parameters[1].Value = model.gid;
			parameters[2].Value = model.orderid;
			parameters[3].Value = model.orderno;
			parameters[4].Value = model.inorderlistid;
			parameters[5].Value = model.storehouseid;
			parameters[6].Value = model.spmaintype;
			parameters[7].Value = model.spsubtype;
			parameters[8].Value = model.productid;
			parameters[9].Value = model.productgid;
			parameters[10].Value = model.productname;
			parameters[11].Value = model.storeall;
			parameters[12].Value = model.price;
			parameters[13].Value = model.hasoutall;
			parameters[14].Value = model.unit;
			parameters[15].Value = model.jgcount;
			parameters[16].Value = model.owneruserid;
			parameters[17].Value = model.lockcout;
			parameters[18].Value = model.dataadduserid;
			parameters[19].Value = model.datadepid;
			parameters[20].Value = model.databranchid;
			parameters[21].Value = model.datadepname;
			parameters[22].Value = model.databranchname;
			parameters[23].Value = model.dataaddusername;
			parameters[24].Value = model.dataaddtime;
			parameters[25].Value = model.insertforlog;
			parameters[26].Value = model.inguid;
			parameters[27].Value = model.id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from herp_store ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from herp_store ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.herp_store GetModel(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,inouttype,gid,orderid,orderno,inorderlistid,storehouseid,spmaintype,spsubtype,productid,productgid,productname,storeall,price,hasoutall,unit,jgcount,owneruserid,lockcout,dataadduserid,datadepid,databranchid,datadepname,databranchname,dataaddusername,dataaddtime,insertforlog,inguid from herp_store ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			hcrainMvc.Model.herp_store model=new hcrainMvc.Model.herp_store();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.herp_store DataRowToModel(DataRow row)
		{
			hcrainMvc.Model.herp_store model=new hcrainMvc.Model.herp_store();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=long.Parse(row["id"].ToString());
				}
				if(row["inouttype"]!=null)
				{
					model.inouttype=row["inouttype"].ToString();
				}
				if(row["gid"]!=null)
				{
					model.gid=row["gid"].ToString();
				}
				if(row["orderid"]!=null && row["orderid"].ToString()!="")
				{
					model.orderid=long.Parse(row["orderid"].ToString());
				}
				if(row["orderno"]!=null)
				{
					model.orderno=row["orderno"].ToString();
				}
				if(row["inorderlistid"]!=null && row["inorderlistid"].ToString()!="")
				{
					model.inorderlistid=long.Parse(row["inorderlistid"].ToString());
				}
				if(row["storehouseid"]!=null && row["storehouseid"].ToString()!="")
				{
					model.storehouseid=long.Parse(row["storehouseid"].ToString());
				}
				if(row["spmaintype"]!=null)
				{
					model.spmaintype=row["spmaintype"].ToString();
				}
				if(row["spsubtype"]!=null)
				{
					model.spsubtype=row["spsubtype"].ToString();
				}
				if(row["productid"]!=null && row["productid"].ToString()!="")
				{
					model.productid=long.Parse(row["productid"].ToString());
				}
				if(row["productgid"]!=null)
				{
					model.productgid=row["productgid"].ToString();
				}
				if(row["productname"]!=null)
				{
					model.productname=row["productname"].ToString();
				}
				if(row["storeall"]!=null && row["storeall"].ToString()!="")
				{
					model.storeall=decimal.Parse(row["storeall"].ToString());
				}
				if(row["price"]!=null && row["price"].ToString()!="")
				{
					model.price=decimal.Parse(row["price"].ToString());
				}
				if(row["hasoutall"]!=null && row["hasoutall"].ToString()!="")
				{
					model.hasoutall=decimal.Parse(row["hasoutall"].ToString());
				}
				if(row["unit"]!=null)
				{
					model.unit=row["unit"].ToString();
				}
				if(row["jgcount"]!=null && row["jgcount"].ToString()!="")
				{
					model.jgcount=decimal.Parse(row["jgcount"].ToString());
				}
				if(row["owneruserid"]!=null && row["owneruserid"].ToString()!="")
				{
					model.owneruserid=long.Parse(row["owneruserid"].ToString());
				}
				if(row["lockcout"]!=null && row["lockcout"].ToString()!="")
				{
					model.lockcout=decimal.Parse(row["lockcout"].ToString());
				}
				if(row["dataadduserid"]!=null && row["dataadduserid"].ToString()!="")
				{
					model.dataadduserid=int.Parse(row["dataadduserid"].ToString());
				}
				if(row["datadepid"]!=null && row["datadepid"].ToString()!="")
				{
					model.datadepid=int.Parse(row["datadepid"].ToString());
				}
				if(row["databranchid"]!=null && row["databranchid"].ToString()!="")
				{
					model.databranchid=int.Parse(row["databranchid"].ToString());
				}
				if(row["datadepname"]!=null)
				{
					model.datadepname=row["datadepname"].ToString();
				}
				if(row["databranchname"]!=null)
				{
					model.databranchname=row["databranchname"].ToString();
				}
				if(row["dataaddusername"]!=null)
				{
					model.dataaddusername=row["dataaddusername"].ToString();
				}
				if(row["dataaddtime"]!=null && row["dataaddtime"].ToString()!="")
				{
					model.dataaddtime=DateTime.Parse(row["dataaddtime"].ToString());
				}
				if(row["insertforlog"]!=null && row["insertforlog"].ToString()!="")
				{
					model.insertforlog=int.Parse(row["insertforlog"].ToString());
				}
				if(row["inguid"]!=null)
				{
					model.inguid=row["inguid"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,inouttype,gid,orderid,orderno,inorderlistid,storehouseid,spmaintype,spsubtype,productid,productgid,productname,storeall,price,hasoutall,unit,jgcount,owneruserid,lockcout,dataadduserid,datadepid,databranchid,datadepname,databranchname,dataaddusername,dataaddtime,insertforlog,inguid ");
			strSql.Append(" FROM herp_store ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM herp_store ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from herp_store T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "herp_store";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

